<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */

$workgroups = $records[0];
$rights = $records['rights'];

$disabledAttribute = 'disabled="disabled"';
?>
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/common.js"></script>
<script type="text/javascript" src="../../scripts/jquery/jquery.js"></script>

<script type="text/javascript">
//<![CDATA[
var baseUrl = '?argcode=workgroup&action=';

function actionShowAdd() {
	//$('addPanel').style.display = 'block';
	$('#addPanel').show();
	document.getElementById('frmAddWorkShift').reset();
}

function cancelAddShift() {
	//$('#addPanel').style.display = 'none';
	$('#addPanel').hide();
	//$('#frmAddWorkShift').reset();
	document.getElementById('frmAddWorkShift').reset();
}

function addShift() {
	err=false;
	msg='<?php echo $lang_Error_PleaseCorrectTheFollowing; ?>\n\n';

	if ($('#txtShiftName').val().trim() == '') {
		err=true;
		msg+="\t- <?php echo $lang_Time_Error_SpecifyWorkShiftName; ?>\n";
	}

	if (err) {
		alert(msg);

		return false;
	}

	//$('#frmAddWorkShift').action=baseUrl+'Add_Work_Group';
	document.getElementById('frmAddWorkShift').action=baseUrl+'Add_Work_Group';
	document.getElementById('frmAddWorkShift').submit();
}

function actionDelete() {
	with (document.frmListOfShifts) {
		check=false;

		for (var i=0; elements.length>i; i++) {
			if ((elements[i].type == 'checkbox') && (elements[i].checked == true)) {
				check = true;
				break;
			}
		}

		if (check) {
			action=baseUrl+'Delete_Work_Group';
			submit();
		} else {
			alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
		}
	}
}

function doHandleAll() {
	with (document.frmListOfShifts) {
		if(elements['allCheck'].checked == false){
			doUnCheckAll();
		}
		else if(elements['allCheck'].checked == true){
			doCheckAll();
		}
	}
}

function doCheckAll() {
	with (document.frmListOfShifts) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox') {
				elements[i].checked = true;
			}
		}
	}
}

function doUnCheckAll() {
	with (document.frmListOfShifts) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox') {
				elements[i].checked = false;
			}
		}
	}
}

//]]>
</script>
<div id="addPanel" class="outerbox" style="width:350px;display:none;">
<div class="mainHeading"><h2><?php echo $lang_Time_WorkShift_Add;?></h2></div>
	<form name="frmAddWorkShift" id="frmAddWorkShift" method="post" action="?argcode=workgroup&amp;action=">
		<div class="roundbox">
			<label for="txtShiftName"><?php echo $lang_Class_Groupname; ?><span class="required">*</span></label>
	        <input type="text" id="txtShiftName" name="txtShiftName" tabindex="1" class="formInputText"/>
            <br class="clear"/>
	        <label for="txtShiftType">班次类别</label>
	        <select name="txtShiftType" id="txtShiftType" tabindex="2">
        		<option value="">选择班次类别</option>
        		<option value="车间1班">车间1班</option>
        		<option value="车间2班">车间2班</option>
        		<option value="车间3班">车间3班</option>
        		<option value="车间4班">车间4班</option>
        		<option value="行政日班">行政日班</option>
        		<option value="行政夜班">行政夜班</option>
        		<option value="保安1班">保安1班</option>
        		<option value="保安2班">保安2班</option>
        		<option value="保安3班">保安3班</option>
        		<option value="保安4班">保安4班</option>
        		<option value="厨房1班">厨房1班</option>
        		<option value="厨房2班">厨房2班</option>
        		<option value="厨房3班">厨房3班</option>
        		<option value="厨房4班">厨房4班</option>
        		<option value="空白班">空白班</option>
        	</select>
            <br class="clear"/>
	        <label for="txtHoursPerDay">组员总数</label>
	        <input type="text" id="txtHoursPerDay" name="txtHoursPerDay" tabindex="3" size="3" class="formInputText" style="width:30px;"/>
            <br class="clear"/>
	        <label for="txtGroupLeader">组长</label>
	        <input type="hidden" name="txtGroupLeader" id="txtGroupLeader" value="" />
	        <input type="text" name="groupLeader" id="groupLeader" class="formInputText" 
			value="" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','groupLeader','ShowUserName','txtGroupLeader')"/><br>
			<div id="ShowUserName" class="shownameclass" style="display:none"><table id="tbname" width="350" border="0" cellspacing="0" cellpadding="0"></table></div>
        	<br class="clear"/>
	        <label for="txtManager">负责经理</label>
	        <input type="hidden" name="txtManager" id="txtManager" value="" />
	        <input type="text" name="manager" id="manager" class="formInputText" 
			value="" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','manager','ShowUserName','txtManager')"/><br>
        	<br class="clear"/>
	        <label for="txtBoss">审批老板</label>
	        <input type="hidden" name="txtBoss" id="txtBoss" value="" />
	        <input type="text" name="boss" id="boss" class="formInputText" 
			value="" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','boss','ShowUserName','txtBoss')"/><br>
        	<br class="clear"/>

	        <label for="none">&nbsp;</label>
	        <input type="hidden" id="none" name="none"/>
            <div class="formbuttons">
            	<?php //$disabled = ($rights['add']) ? '' : $disabledAttribute; ?>
                <input type="button" class="addbutton" id="addBtn" <?php //echo $disabled; ?>
                    onclick="addShift();" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
                    value="<?php echo $lang_Common_Add;?>" />
                <input type="button" class="cancelbutton" onclick="cancelAddShift();" <?php //echo $disabled; ?>
                    onmouseover="moverButton(this);" onmouseout="moutButton(this);"
                     value="<?php echo $lang_Common_Cancel;?>" />
            </div>
            <br class="clear"/>
	   	</div>
	</form>
</div>


<div class="formpage3col">
    <div class="outerbox">
        <div class="mainHeading"><h2><?php echo $lang_Time_WorkShifts;?></h2></div>

    <?php
        if (isset($_GET['message']) && !empty($_GET['message'])) {
            $message  = $_GET['message'];
            $messageType = CommonFunctions::getCssClassForMessage($message);
            $message = "lang_Time_Errors_" . $message;
    ?>
        <div class="messagebar">
            <span class="<?php echo $messageType; ?>"><?php echo (isset($$message)) ? $$message: CommonFunctions::escapeHtml($_GET['message']); ?></span>
        </div>
    <?php } ?>

   <div class="actionbar">
        <div class="actionbuttons">
        	<?php $disabled = ($rights['add']) ? '' : $disabledAttribute; ?>
            <input type="button" class="addbutton" <?php //echo $disabled; ?>
                onclick="actionShowAdd();"
                name="btnAdd" id="btnAdd"
                onmouseover="moverButton(this);" onmouseout="moutButton(this);"
                value="<?php echo $lang_Common_Add;?>" />
			<?php $disabled = ($rights['delete']) ? '' : $disabledAttribute; ?>
                <input type="button" class="delbutton" <?php //echo $disabled; ?>
                    name="btnDel" id="btnDel" alt="Delete"
                    onclick="actionDelete();"
                    onmouseover="moverButton(this);" onmouseout="moutButton(this);"
                    value="<?php echo $lang_Common_Delete;?>" />
        </div>
        <div class="noresultsbar"><?php echo (count($workgroups) == 0) ? $lang_Error_NoRecordsFound : '';?></div>
        <div class="pagingbar"></div>
    <br class="clear" />
    </div>
    <br class="clear" />
  <form id="frmListOfShifts" name="frmListOfShifts" method="post" action="?argcode=workgroup&amp;action=">
	<table border="0" cellpadding="0" cellspacing="0" class="data-table">
		<thead>
			<tr>
		    	<td width="25"><input type="checkbox" class="checkbox" name="allCheck" value="" onclick="doHandleAll();" /></td>
		    	<td width="80"><?php echo $lang_Class_Groupname; ?></td>
		    	<td width="80">班次类别</td>
		    	<td width="80"><?php echo $lang_Class_EmpQuantity; ?></td>
		    	<td width="400" align="center"><?php echo $lang_Class_Employees; ?></td>
		    	<td width="80">组长</td>
		    	<td width="80">负责经理</td>
		    	<td width="80">审批老板</td>
			</tr>
		</thead>
		<tbody>
		<?php
		if (count($workgroups) > 0) {
			$i=0;
			foreach ($workgroups as $workgroup) {
				if(!($i%2)) {
					$cssClass = 'odd';
			 	} else {
			 		$cssClass = 'even';
			 	}
			 	$i++;
			 	$employees = $workgroup->getAssignedEmployees();
			 	$names = array();
			 	foreach ($employees as $employee) {
			 		$names[] = $employee['emp_lastname'].$employee['emp_firstname'];
			 	}
			 	$names = implode(',',$names);
		?>
			<tr>
		    	<td class="<?php echo $cssClass; ?>"><input type="checkbox" id="deleteShift_<?php echo $i;?>" name="deleteShift[]" value="<?php echo $workgroup->getWorkgroupId(); ?>" /></td>
		    	<td class="<?php echo $cssClass; ?>"><a href="?argcode=workgroup&amp;action=View_Edit_Work_Group&amp;id=<?php echo $workgroup->getWorkgroupId(); ?>"><?php echo $workgroup->getName(); ?></a></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $workgroup->getGroupType(); ?></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $workgroup->getEmployeeQuantity(); ?></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $names; ?></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $workgroup->getGroupLeader(); ?></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $workgroup->getManager(); ?></td>
		    	<td class="<?php echo $cssClass; ?>"><?php echo $workgroup->getBoss(); ?></td>
			</tr>
		<?php
			}
		}
		?>
		</tbody>
	</table>
  </form>
  </div>
</div>

<script type="text/javascript">
//<![CDATA[
    if (document.getElementById && document.createElement) {
        roundBorder('outerbox');
    }
//]]>
</script>
